package com.haonan.controller;


import com.haonan.pojo.entily.Dept;
import com.haonan.pojo.entily.Result;
import com.haonan.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController//组合注解将返回值转换成json
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;
    @GetMapping
    public Result findAll(){
        List<Dept> list = deptService.findAll();
        return Result.success(list);
    }
    @DeleteMapping
    public Result deleteById(@RequestParam("id") Integer id){
        deptService.deleteById(id);
        return Result.success();
    }
    @PostMapping
    public Result save(@RequestBody  Dept dept){
        deptService.save(dept);
        return Result.success();
    }
    //先查找部门信息
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id){
        Dept dept = deptService.findById(id);
        return Result.success(dept);
    }
    //编辑部门信息
    @PutMapping
    public Result update(@RequestBody Dept dept){
        deptService.update(dept);
        return Result.success();
    }
}
